package domain;

import java.util.Date;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;

import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Access(AccessType.PROPERTY)
public class Ownership extends DomainEntity {
	
	// Constructors -----------------------------------------------------------

	public Ownership(){
		super();
	}
	
	// Attributes -------------------------------------------------------------
	
	private Date startDate;
	private Date finishDate;
	
	@NotNull
	@Past
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm")
	public Date getStartDate() {
		return startDate;
	}
	
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm")
	public Date getFinishDate() {
		return finishDate;
	}
	
	public void setFinishDate(Date finishDate) {
		this.finishDate = finishDate;
	}
		
	// Relationships ----------------------------------------------------------

	private Customer legalOwner;
	private Painting ownedPainting;

	@NotNull
	@Valid
	@ManyToOne(optional = false)
	public Customer getLegalOwner() {
		return legalOwner;
	}

	public void setLegalOwner(Customer legalOwner) {
		this.legalOwner = legalOwner;
	}

	@NotNull
	@Valid
	@ManyToOne(optional = false, cascade=CascadeType.ALL)
	public Painting getOwnedPainting() {
		return ownedPainting;
	}

	public void setOwnedPainting(Painting ownedPainting) {
		this.ownedPainting = ownedPainting;
	}
	
	

}
